#include "econtainer.h"

eContainer::eContainer(int x,int y,int w,int h,bool hareket_,bool psizable) : Fl_Group(x,y,w,h)
{
    box(FL_PLASTIC_DOWN_BOX);
    color(FL_SELECTION_COLOR);
    cR=0;
    cB=0;
    cG=0;
    cAlpha=0;
    //sahip=parent();
    sildelete=false;
    hareket=hareket_;
    b1 = new eDragBox(x, y, TL);
    b2 = new eDragBox(x+w-10, y+h-10, BR);
    inner = new Fl_Group(x+5, y+5, w-10, h-10);
        metinkutusu=new Fl_Multiline_Input(x+5,y+5,w-10,h-10);
        metinkutusu->box(FL_EMBOSSED_BOX);
        metinkutusu->textsize(12);
    inner->end();
    inner->box(FL_THIN_DOWN_BOX);
    resizable(inner);
    sizable=psizable;
    end();
    tx=metinkutusu->x();
    ty=metinkutusu->y()-60;

    yatay=2;
    dikey=2;
}

eContainer::~eContainer()
{
    delete metinkutusu;
    delete b1;
    delete b2;
    delete inner;
}

int eContainer::handle(int event)
{
    Fl_Gel_Tabs *ps=(Fl_Gel_Tabs *)parent()->parent();
    Cetele *p=(Cetele *)parent();
    Form *pp=(Form *)ps->parent();
    int ret=Fl_Group::handle(event);
    if(ret)
        return ret;
    static int butx=0;
    static int buty=0;
    switch(event)
    {
        case FL_PUSH:
            butx=x()-Fl::event_x();
            buty=y()-Fl::event_y();
            pp->textX(metinkutusu->x());
            pp->textY(metinkutusu->y()-60);
            pp->textW(metinkutusu->w());
            pp->textH(metinkutusu->h());
            pp->textR(cR);
            pp->textG(cG);
            pp->textB(cB);
            pp->textAlpha(cAlpha);
            pp->textScrollv(yatay);
            pp->textScrollh(dikey);
            pp->textPage()->activate();
            ret=1;
            break;
        case FL_DRAG:
            int xx=butx+Fl::event_x();
            int yy=buty+Fl::event_y();
            if(xx>=ps->x() && yy>=ps->y()+20 && xx<=ps->w()+170 && yy<=ps->h()-20 && hareket)
            {
                pp->textX(metinkutusu->x());
                pp->textY(metinkutusu->y()-60);
                pp->textW(metinkutusu->w());
                pp->textH(metinkutusu->h());
                position(xx,yy);
                ps->redraw();
            }
            ret=1;
            break;
        case FL_KEYDOWN:
            if(Fl::event_key()==FL_Delete)
                sildelete=true;
            break;
    }
    return ret;
}
Fl_Multiline_Input * eContainer::kutumetin()
{
    return metinkutusu;
}
int eContainer::cr()
{
    return cR;
}
int eContainer::cg()
{
    return cG;
}
int eContainer::cb()
{
    return cB;
}
int eContainer::calpha()
{
    return cAlpha;
}
int eContainer::cyatay()
{
    return yatay;
}
int eContainer::cdikey()
{
    return dikey;
}
void eContainer::cr(int pr)
{
    cR=pr;
}
void eContainer::cg(int pg)
{
    cG=pg;
}
void eContainer::cb(int pb)
{
    cB=pb;
}
void eContainer::calpha(int palpha)
{
    cAlpha=palpha;
}
void eContainer::cdikey(int pdikey)
{
    dikey=pdikey;
}
void eContainer::cyatay(int pyatay)
{
    yatay=pyatay;
}
bool eContainer::deletesil()
{
    return sildelete;
}
void eContainer::deletesil(bool p)
{
    sildelete=p;
}
